package cyou.breathe.blog.article.domain.entity;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.annotation.TableName;
import cyou.breathe.blog.api.article.constant.ArticleStateEnum;
import cyou.breathe.blog.api.article.request.ArticleCreateRequest;
import cyou.breathe.blog.api.article.request.ArticleUpdateRequest;
import cyou.breathe.blog.datasource.domain.entity.BaseEntity;
import lombok.Getter;
import lombok.Setter;

/**
 * 文章实体
 * @author: breathe
 * @createTime: 2025-08-29
 */
@Setter
@Getter
@TableName("articles")
public class Article extends BaseEntity {

    private Long authorId;

    private Long folderId;

    private String title;

    private String content;

    private String tags;

    private ArticleStateEnum state;


    public Article createArticle(ArticleCreateRequest articleCreateRequest) {
        this.authorId = articleCreateRequest.getAuthorId();
        this.folderId = articleCreateRequest.getFolderId();
        this.title = articleCreateRequest.getTitle();
        this.content = articleCreateRequest.getContent();
        this.tags = JSON.toJSONString(articleCreateRequest.getTags());
        this.state = articleCreateRequest.getState();
        return this;
    }

    public Article updateArticle(ArticleUpdateRequest articleUpdateRequest) {
        this.content = articleUpdateRequest.getContent();
        this.folderId = articleUpdateRequest.getFolderId();
        this.tags = JSON.toJSONString(articleUpdateRequest.getTags());
        this.title = articleUpdateRequest.getTitle();
        this.state = articleUpdateRequest.getState();
        return this;
    }
}